home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / linkedit / linkedit.lha / link-edit / LinkEdit / Link / link_event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-13  |  2.9 KB  |  149 lines

  1. #include <stdio.h>
  2. #include <X11/Xlib.h>
  3. #include "link_types.h"
  4. #include "link_global.h"
  5.  
  6.  
  7. LinkEvent(gnrc,event)
  8.  
  9. LinkStatus *gnrc;
  10. XEvent *event;
  11.  
  12. {
  13.   XWindowAttributes xwa;
  14.   XWindowChanges xwc;
  15.   int i;
  16.  
  17.   switch(event->type) {
  18.  
  19.      case Expose:
  20.  
  21.        if(event->xexpose.count > 0) {
  22.           break;
  23.          }
  24.        if(event->xexpose.window == gnrc->TitleWindow) {
  25.           ReDrawLinkTitleWindow(gnrc);
  26.           break;
  27.          }
  28.  
  29.        if(event->xexpose.window == gnrc->MessageWindow) {
  30.           ReDrawLinkMessageWindow(gnrc);
  31.           break;
  32.          }
  33.  
  34.        if(event->xexpose.window == gnrc->TopWindow) {
  35.           ReDrawLinkTopWindow(gnrc);
  36.           break;
  37.          }
  38.  
  39.        break;
  40.  
  41.      case ButtonPress:
  42.        if(event->xbutton.window == gnrc->TopWindow) {
  43.           LinkButtonPress(gnrc,event);
  44.           break;
  45.          }
  46.  
  47.        break;
  48.  
  49.      case ConfigureNotify:
  50.        if(event->xconfigure.window == gnrc->TopWindow) {
  51.           ReDrawLinkMessageWindow(gnrc);
  52.           ReDrawLinkTitleWindow(gnrc);
  53.          }
  54.   
  55.        break;
  56.  
  57.      default:
  58.        break;
  59.     }
  60.  
  61. }
  62.  
  63.  
  64. LinkUrgentWindowDialogue(gnrc,prompt_string,return_string)
  65.  
  66. LinkStatus *gnrc;
  67. char *prompt_string,*return_string;
  68.  
  69. /* Routine returns the length of the dialogue string */
  70.  
  71. {
  72.  
  73.   int x,y,pstn;
  74.   char chrctr[2];
  75.   XFontStruct *fontstruct;
  76.   XEvent event;
  77.   XWindowAttributes xwa;
  78.   XWindowChanges xwc;
  79.  
  80.   if(gnrc->UrgentWindow == (Window) 0) return(0);
  81.  
  82.   XGetWindowAttributes(dpy,gnrc->TopWindow,&xwa);
  83.   xwc.width = xwa.width;
  84.   xwc.y = xwa.height/2;
  85.  
  86.   XConfigureWindow(dpy,gnrc->UrgentWindow,(CWWidth|CWY),&xwc);
  87.  
  88.   XMapRaised(dpy,gnrc->UrgentWindow);
  89.  
  90.   XGrabKeyboard(dpy,gnrc->UrgentWindow,False,
  91.                 GrabModeAsync,GrabModeAsync,
  92.                 CurrentTime);
  93.  
  94.   XDrawString(dpy,gnrc->UrgentWindow,gnrc->gc,
  95.               LINK_PAD,LINK_PAD+gnrc->fth,prompt_string,
  96.               strlen(prompt_string));
  97.  
  98.   /* Edit the filename */
  99.  
  100.   fontstruct = gnrc->fontstruct;
  101.  
  102.   pstn = 0;
  103.   chrctr[0] = 0;
  104.   chrctr[1] = 0;   /* for string manipulation */
  105.  
  106.   y = LINK_PAD + gnrc->fth;
  107.   x = LINK_PAD + XTextWidth(fontstruct,prompt_string,strlen(prompt_string));
  108.  
  109.  
  110.   while(chrctr[0] != '\r') {
  111.  
  112.      if((chrctr[0] >= 32) && (chrctr[0] <= 126)) {
  113.  
  114.         XDrawString(dpy,gnrc->UrgentWindow,
  115.                     gnrc->gc,x,y,chrctr,1);
  116.  
  117.         x += XTextWidth(fontstruct,chrctr,1);
  118.  
  119.         return_string[pstn] = chrctr[0];
  120.         pstn++;
  121.  
  122.        }
  123.  
  124.      if((chrctr[0] == 8) || (chrctr[0] == 127)) {
  125.  
  126.         if(pstn > 0) {
  127.            pstn--;
  128.            x -= XTextWidth(fontstruct,&(return_string[pstn]),1);
  129.            XDrawImageString(dpy,gnrc->UrgentWindow,
  130.                             gnrc->gc,x,y," ",1);
  131.           }
  132.  
  133.        }
  134.  
  135.      XMaskEvent(dpy,KeyPressMask,&event);
  136.      if(XLookupString(&(event.xkey),chrctr,1,NULL,NULL) == 0) {
  137.         chrctr[0] = 0;
  138.        }
  139.     }
  140.  
  141.   return_string[pstn] = 0;
  142.  
  143.   XUngrabKeyboard(dpy,CurrentTime);
  144.   XUnmapWindow(dpy,gnrc->UrgentWindow);
  145.  
  146.   return(pstn);
  147.  
  148. }
  149.